package com.abdeafan.anekdot_01;

import java.util.ArrayList;
import java.util.Random;

import android.content.res.Resources;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.Toast;

public class PageFragment extends Fragment {
    static final String ARGUMENT_PAGE_NUMBER = "arg_page_number";
    int pageNumber;
    int backColor;
//    Resources anekdot_list_res = getResources();
//    String[] anekdot = anekdot_list_res.getStringArray(R.array.anekdot_list);

    static PageFragment newInstance(int page) {
        PageFragment pageFragment = new PageFragment();
        Bundle arguments = new Bundle();
        arguments.putInt(ARGUMENT_PAGE_NUMBER, page);
        pageFragment.setArguments(arguments);
        return pageFragment;
    }
    @Override  public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        pageNumber = getArguments().getInt(ARGUMENT_PAGE_NUMBER);
        Random rnd = new Random();
        backColor = Color.argb(40, rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256));


        SeekBar myseek1 = null;
        myseek1 = (SeekBar) findViewById(R.id.seek1);
        Resources anekdot_list_res = getResources();
        String[] anekdot = anekdot_list_res.getStringArray(R.array.anekdot_list);
        myseek1.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            int progressChanged = 0;

            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                progressChanged = progress;
                TextView tvPage = (TextView) findViewById(R.id.tvPage);
                tvPage.setText(anekdot[seekBar.getProgress()]);
            }

            public void onStartTrackingTouch(SeekBar seekBar) {
                // TODO Auto-generated method stub
            }

            public void onStopTrackingTouch(SeekBar seekBar) {
                Toast.makeText(MyActivity.this, "seek bar progress:" + progressChanged,
                        Toast.LENGTH_SHORT).show();
            }
        });



    }
    @Override
             public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        Resources anekdot_list_res = getResources();
        String[] anekdot = anekdot_list_res.getStringArray(R.array.anekdot_list);
        View view = inflater.inflate(R.layout.fragment, null);
        TextView tvPage = (TextView) view.findViewById(R.id.tvPage);
        tvPage.setText(anekdot[pageNumber].toString());
        tvPage.setBackgroundColor(backColor);
        return view;
    }
}